import { EDITOR_ELEMENT_TYPE, PLUGINS_KEYS, Plugin } from '../types';

function StyleBase(): Plugin {
  return {
    key: PLUGINS_KEYS.STYLEBASE,
    type: EDITOR_ELEMENT_TYPE.INLINE,
    matchLeaf: (props) => !!props.leaf[PLUGINS_KEYS.STYLEBASE],
    renderLeaf: (context) => {
      const styles = context.props.leaf[PLUGINS_KEYS.STYLEBASE] || {};
      for (const item of Object.keys(styles)) {
        // eslint-disable-next-line @typescript-eslint/ban-ts-comment
        // @ts-ignore
        context.style[item] = styles[item];
      }
      return context.children;
    },
  };
}

export default StyleBase;
